package com.hljx.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hljx.config.Result;
import com.hljx.dto.AccountingUnitDTO;
import com.hljx.dto.AccountingUnitPageDTO;
import com.hljx.dto.ExportAccountingUnitDTO;
import com.hljx.dto.HospitalDataDTO;
import com.hljx.entity.SysHospitalArea;
import com.hljx.service.SysAccountingUnitService;
import com.hljx.service.SysBindService;
import com.hljx.service.SysDictService;
import com.hljx.service.SysHospitalAreaService;
import com.hljx.vo.AccountingUnitsVO;
import com.hljx.vo.DictTypeVO;
import com.hljx.vo.HospitalDataVO;
import com.hljx.vo.TargetSysDictVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 核算单元管理 前端控制器
 * </p>
 *
 * @author gx
 * @since 2023-09-18
 */
@RestController
@RequestMapping("/sysAccountingUnit")
@Tag(name = "核算单元管理")
public class SysAccountingUnitController {

    @Autowired
    SysAccountingUnitService service;

    @Autowired
    SysHospitalAreaService hospitalAreaService;

    @Autowired
    SysDictService sysDictService;

    @GetMapping("/listHospitalArea")
    @Operation(summary = "院区下拉框")
    public Result<List<SysHospitalArea>> listHospitalArea() {
        return Result.success(hospitalAreaService.listHospitalArea());
    }

    @GetMapping("/categoryDropDown")
    @Operation(summary = "类别下拉框")
    public Result<List<DictTypeVO>> categoryDropDown() {
        return Result.success(sysDictService.selectDictDropdown("类别"));
    }

    @Operation(summary = "保存或编辑核算单元")
    @PostMapping("/saveOrUpdate")
    public Result<Boolean> saveOrUpdate(@RequestBody AccountingUnitDTO accountingUnitDTO) {
        return Result.success(service.saveOrUpdate(accountingUnitDTO));
    }
    @Operation(summary = "分页查询核算单元")
    @PostMapping("/listAccountingUnitByPage")
    public Result<IPage<AccountingUnitsVO>> listAccountingUnitByPage(@RequestBody AccountingUnitPageDTO accountingUnitPageDTO) {
        return Result.success(service.listAccountingUnitByPage(accountingUnitPageDTO));
    }

    @Operation(summary = "删除核算单元")
    @GetMapping("/removeAccountingById")
    public Result<Boolean> removeAccountingById(@RequestParam("id") Long id) {
        return Result.success(service.removeAccountingById(id));
    }

    @Operation(summary = "导出和下载模板")
    @PostMapping("/export")
    public void export(@RequestBody ExportAccountingUnitDTO dto, HttpServletResponse response) throws ClassNotFoundException {
        service.export(dto,response);
    }


    @Operation(summary = "导入")
    @PostMapping("/importExcel")
    public void importExcel(@RequestParam("file") MultipartFile file, HttpServletResponse response) throws ClassNotFoundException, IOException {
        service.importExcel(file,response);
    }

    @Operation(summary = "指标管理-工作量指标管理-新增编辑科室下拉框")
    @GetMapping("/sysAccountingUnitPull")
    public Result sysAccountingUnitPull(){
        List<TargetSysDictVO> targetSysDictVOS = service.sysAccountingUnitPull();
        return Result.success(targetSysDictVOS);
    }



    @Operation(summary = "指标管理-工作量指标管理-新增编辑开单执行科室下拉框")
    @GetMapping("/HISDeptCode")
    public Result HISDeptCode(){
        List<TargetSysDictVO> targetSysDictVOS = service.HISDeptCode();
        return Result.success(targetSysDictVOS);
    }

}
